/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * AdministracionBD.java
 *
 * Created on 20/05/2011, 05:48:34 AM
 */
package repproyectobases;



/**
 *
 * @author Bladelaire
 */
public class AdministracionBD extends javax.swing.JInternalFrame {

    private Control ctrl;
    static private Interfaz in;
    private int x=0;
    private int cent=0;
    private Detalle detalle; 
    
    /** Creates new form AdministracionBD */
    public AdministracionBD(Control ctrl,Interfaz miIn) 
    {
        this.ctrl=ctrl;
        AdministracionBD.in=miIn;
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        buttonGroup2 = new javax.swing.ButtonGroup();
        jLabel1 = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        jRadioButton1 = new javax.swing.JRadioButton();
        jRadioButton2 = new javax.swing.JRadioButton();
        jRadioButton3 = new javax.swing.JRadioButton();
        jRadioButton4 = new javax.swing.JRadioButton();
        jRadioButton5 = new javax.swing.JRadioButton();
        jLabel2 = new javax.swing.JLabel();
        jSeparator2 = new javax.swing.JSeparator();
        jRadioButton6 = new javax.swing.JRadioButton();
        jRadioButton7 = new javax.swing.JRadioButton();
        jButton1 = new javax.swing.JButton();

        setTitle("Bienvenido \"x\" a la seccion de administracion de la BD de QuindiMotos");
        setPreferredSize(new java.awt.Dimension(556, 330));

        jLabel1.setText("Seleccione la seccion a administrar:");

        buttonGroup1.add(jRadioButton1);
        jRadioButton1.setText("Facturas de ventas realizadas");

        buttonGroup1.add(jRadioButton2);
        jRadioButton2.setText("Empleados o Clientes");
        jRadioButton2.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jRadioButton2ItemStateChanged(evt);
            }
        });

        buttonGroup1.add(jRadioButton3);
        jRadioButton3.setText("Repuestos");

        buttonGroup1.add(jRadioButton4);
        jRadioButton4.setText("Motos");

        buttonGroup1.add(jRadioButton5);
        jRadioButton5.setText("Proveedores");

        jLabel2.setText("Especifique la infomracion extra de la seleccion:");

        buttonGroup2.add(jRadioButton6);
        jRadioButton6.setText("Empleados");
        jRadioButton6.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jRadioButton6ItemStateChanged(evt);
            }
        });

        buttonGroup2.add(jRadioButton7);
        jRadioButton7.setText("Clientes");

        jButton1.setText("Ingresar");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jRadioButton7)
                            .addComponent(jRadioButton6)
                            .addComponent(jSeparator2, javax.swing.GroupLayout.DEFAULT_SIZE, 520, Short.MAX_VALUE)
                            .addComponent(jRadioButton5)
                            .addComponent(jRadioButton4)
                            .addComponent(jRadioButton3)
                            .addComponent(jSeparator1, javax.swing.GroupLayout.DEFAULT_SIZE, 520, Short.MAX_VALUE)
                            .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 379, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jRadioButton2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jRadioButton1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 282, Short.MAX_VALUE))))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(232, 232, 232)
                        .addComponent(jButton1)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jRadioButton1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jRadioButton2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jRadioButton3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jRadioButton4)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jRadioButton5)
                .addGap(18, 18, 18)
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jRadioButton6)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jRadioButton7)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jButton1)
                .addContainerGap(25, Short.MAX_VALUE))
        );

        jLabel2.setVisible(false);
        jSeparator2.setVisible(false);
        jRadioButton6.setVisible(false);
        jRadioButton7.setVisible(false);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        if(evt.getSource()==jButton1)
        {
            if(jRadioButton1.isSelected())
            {
                x=1;
                //System.out.println("X: "+x);
            }
            if(jRadioButton2.isSelected()&&jRadioButton6.isSelected())
            {
                x=2;
                //System.out.println("X: "+x);
            }
            if(jRadioButton2.isSelected()&&jRadioButton7.isSelected())
            {
                x=3;
                //System.out.println("X: "+x);
            }
            if(jRadioButton3.isSelected())
            {
                x=4;
                //System.out.println("X: "+x);
            }
            if(jRadioButton4.isSelected())
            {
                x=5;
                //System.out.println("X: "+x);
            }
            if(jRadioButton5.isSelected())
            {
                x=6;
                //System.out.println("X: "+x);
            }
            if(x!=0)
            {
                if(cent>0)
                {
                    System.out.println("XV1: "+x);
                    detalle=Detalle.getDetalle(ctrl, x, in, this);
                    detalle.setView(x);
                    detalle.repaint();
                    detalle.show();
                    thisHide();
                }
                else
                {
                    cent++;
                    System.out.println("XV"+(cent+1)+": "+x);
                    detalle=Detalle.getDetalle(ctrl, x, in, this);
                    in.getInternalPanel().add(detalle);
                    detalle.show();
                    thisHide();
                }     
            }
        }
    }//GEN-LAST:event_jButton1ActionPerformed

    private void thisHide()
    {
        if(!jRadioButton2.isSelected())
        {
            jLabel2.setVisible(false);
            jSeparator2.setVisible(false);
            jRadioButton6.setVisible(false);
            jRadioButton7.setVisible(false);
        }
        this.hide();
    }
    
    private void jRadioButton6ItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jRadioButton6ItemStateChanged
        if(evt.getSource()==jRadioButton2&&jRadioButton2.isSelected())
        {
            jLabel2.setVisible(true);
            jSeparator2.setVisible(true);
            jRadioButton6.setVisible(true);
            jRadioButton7.setVisible(true);
        }
        else
        {
            if(evt.getSource()==jRadioButton2&&!jRadioButton2.isSelected())
            {
                jLabel2.setVisible(false);
                jSeparator2.setVisible(false);
                jRadioButton6.setVisible(false);
                jRadioButton7.setVisible(false);
            } 
        }
    }//GEN-LAST:event_jRadioButton6ItemStateChanged

    private void jRadioButton2ItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jRadioButton2ItemStateChanged
        if(evt.getSource()==jRadioButton2&&jRadioButton2.isSelected())
        {
            jLabel2.setVisible(true);
            jSeparator2.setVisible(true);
            jRadioButton6.setVisible(true);
            jRadioButton7.setVisible(true);
        }
        else
        {
            if(evt.getSource()==jRadioButton2&&!jRadioButton2.isSelected())
            {
                jLabel2.setVisible(false);
                jSeparator2.setVisible(false);
                jRadioButton6.setVisible(false);
                jRadioButton7.setVisible(false);
            } 
        }
    }//GEN-LAST:event_jRadioButton2ItemStateChanged

    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.ButtonGroup buttonGroup2;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JRadioButton jRadioButton1;
    private javax.swing.JRadioButton jRadioButton2;
    private javax.swing.JRadioButton jRadioButton3;
    private javax.swing.JRadioButton jRadioButton4;
    private javax.swing.JRadioButton jRadioButton5;
    private javax.swing.JRadioButton jRadioButton6;
    private javax.swing.JRadioButton jRadioButton7;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    // End of variables declaration//GEN-END:variables

}
